from  rest_framework import serializers
from  sclass.models import  Class

class SclassSerializer(serializers.Serializer):

    id = serializers.IntegerField(read_only=True)
    title = serializers.CharField(required=False, allow_blank=True, max_length=100)
    code = serializers.CharField(required=False,allow_blank=True)
    students = serializers.IntegerField(required=False)


    def create(self, validated_data):
        return Class.objects.create(**validated_data)


    def update(self, instance, validated_data):
        instance.title = validated_data.get('title', instance.title)
        instance.code = validated_data.get('code', instance.code)
        instance.students = validated_data.get('students', instance.students)
        print(instance.title)
        print(instance.code)
        print(instance.students)
        print("---------------------------------------")

        instance.save()
        return instance



